/*
 * In number theory, a perfect number is a positive integer that is equal to
 * the sum of its proper positive divisors, that is, the sum of its positive
 * divisors excluding the number itself (also known as its aliquot sum).
 * Equivalently, a perfect number is a number that is half the sum of all of
 * its positive divisors (including itself).
 */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>

#define BASE 0xA

int
main(int argc, char **argv)
{
	long long n;
	register long long next = 6, i, sum;

	if (argc == 2)
		n = strtoll(argv[1], NULL, BASE);
	else
		(void) scanf("%lld", &n);

	while (n--) {
		while (1) { /* yah, i know... */
			sum = 1;
			for (i = 2 ; i <= (next + 1) / 2 ; ++i) {
				if (next % i == 0) {
					sum += i;
				}
			}

			if (sum == next)
				break;
			(void) printf("\r next=%lld", ++next);
			(void) fflush(NULL);
		}
		(void) printf(" next=%lld is PERFECT\n", next++);
	}

	return (0);
}
